class Solution
{
public:
    int numSpecial(vector<vector<int>> &mat)
    {
        int rows = mat.size();
        int cols = mat[0].size();
        vector<int> rowSum(rows, 0);
        vector<int> colSum(cols, 0);
        for (int row = 0; row < rows; ++row)
        {
            for (int col = 0; col < cols; ++col)
            {
                rowSum[row] += mat[row][col];
                colSum[col] += mat[row][col];
            }
        }

        int specialPosCount = 0;
        for (int row = 0; row < rows; ++row)
        {
            for (int col = 0; col < cols; ++col)
            {
                if (mat[row][col] == 1 && rowSum[row] == 1 && colSum[col] == 1)
                {
                    ++specialPosCount;
                }
            }
        }
        return specialPosCount;
    }
};